package org.rcloud.io.service.impl;

import org.rcloud.io.Utils.PageVo;
import org.rcloud.io.Utils.ResultVo;
import org.rcloud.io.mapper.HomestayfileMapper;
import org.rcloud.io.model.Homestayfile;
import org.rcloud.io.service.HomestayfileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2019/3/21.
 */
@Service(value = "HomestayfileService")
public class HomestayfileServiceImpl implements HomestayfileService{

    @Autowired
    private HomestayfileMapper homestayfileMapper;

    @Override
    public ResultVo save(Homestayfile homestayfile) {

        if (homestayfile.equals("") || homestayfile == null) {
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                int i = homestayfileMapper.insertSelective(homestayfile);
                return ResultVo.setOK(i);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public PageVo<Homestayfile> findFileByNum(String id) {
        try {
            List<Homestayfile> list = homestayfileMapper.selectByNum(id);
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }
    }

    @Override
    public ResultVo updateFile(int id) {

        try {
            int i = homestayfileMapper.updateById(id);
            return ResultVo.setOK(i);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }

    @Override
    public ResultVo findFileById(int id) {

        try {
            Homestayfile homestayfile = homestayfileMapper.selectByPrimaryKey(id);
            return ResultVo.setOK(homestayfile);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }

    @Override
    public ResultVo updateFlagAll(String eid) {

        try {
            int i = homestayfileMapper.updateFlagAll(eid);
            return ResultVo.setOK(i);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }

    @Override
    public ResultVo updateFlag(int id) {

        try {
            int i = homestayfileMapper.updateFlag(id);
            return ResultVo.setOK(i);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }
    }
}
